import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/modules/state/dependency_create/counter_controller.dart';

class DependencyCreatePage extends GetView {

  @override
  Widget build(BuildContext context) {
    final c = Get.put(CounterController());
    final c1 = Get.find<CounterController>();
    final c2 = Get.find<CounterController>();

    // 通过 Get.create 创建实例
    Get.create(() => PageController());
    final c3 = Get.find<PageController>();
    final c4 = Get.find<PageController>();

    return Scaffold(
      appBar: AppBar(title: Text('DependencyCreatePage')),

      body: SafeArea(
        child: Column(
          children: [
            ListTile(
              title: Text('Get.put'),
              subtitle: Text('Get.put(CounterController())'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.defaultDialog(
                  content: Text('结果：'+(c1 == c2).toString()),
                  onConfirm: () => Get.back()
                );
              },
            ),

            ListTile(
              title: Text('Get.create'),
              subtitle: Text('Get.create(() => PageController())'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.defaultDialog(
                  content: Text('结果：'+(c3 == c4).toString()),
                  onConfirm: () => Get.back()
                );
              },
            ),
          ],
        )
      )
    );
  }
}